import java.io.ByteArrayInputStream;
import java.util.Scanner;

import org.yaz4j.Connection;
import org.yaz4j.PrefixQuery;
import org.yaz4j.Record;
import org.yaz4j.ResultSet;


public class Main {

	public static void main(String[] args) {
//		SessionFactory fact = HibernateFactory.getSessionFactory();
//		
//		Session sess = fact.openSession();
//		
//		org.hibernate.Query q = sess.createQuery("from Serial  where issn='102321'");
//		
//		for (Object obj : q.list()) {
//			Serial s = (Serial) obj;
//			for (Volume v : s.getVolumes())
//				System.out.println(s.getTitle() + "->" + v.getTitle());
//		}
//		fact.close();
		docUsoDoYAZ4J();
	}
	
	public static void docUsoDoYAZ4J() {
		Connection conn = new Connection("z3950.loc.gov", 7090);
		conn.setDatabaseName("Voyager");
		conn.setSyntax("usmarc");
		
	     PrefixQuery pqf = new PrefixQuery("@attr 1=4 resourse");
	     ResultSet set = conn.Search(pqf);
	     Record rec =  set.getRecord(0);
	     ByteArrayInputStream input = new ByteArrayInputStream(rec.getContent());
	     int i;
	     while ( (i = input.read()) != -1)
	     System.out.print((char)i);
		
		/*
		System.out.print("Escolher por (1 Autor) (2 Titulo) (3 ISBN) (4 ISSN): ");
		Scanner sc = new Scanner(System.in);
		int choice = Integer.parseInt(sc.nextLine().trim());

		System.out.print("Digite sua busca: ");
		String query = "\"" + sc.nextLine().trim() + "\"";
		switch(choice) {
		case 1: query = "@attr 1=1 " + query; break;
		case 2: query = "@attr 1=4 " + query; break;
		case 3: query = "@attr 1=7 " + query; break;
		case 4: query = "@attr 1=8 " + query; break;
		}
		
		PrefixQuery q = new PrefixQuery(query);
		ResultSet rs = conn.Search(q);
		System.out.println("Tamanho: " + rs.getSize());
		for (int i = 0; i < rs.getSize(); i++) {
			System.out.println("--------------------");
			System.out.println(rs.getRecord(i).render());
		}*/
	}
	
}
